package com.example.demo.setstudy;

import java.util.Comparator;
import java.util.TreeSet;

/**
 * @Description StudentTest2
 * @Author songchuanlong
 * @Date 2025-05-12
 */
public class StudentTest2 {
    public static void main(String[] args) {
        //TreeSet就近选择自已自带的比较器对象进行排序(new和实现Comparable，只会执行new)
        TreeSet<Student> students = new TreeSet<>(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                return Double.compare(o1.getHeight(),o2.getHeight());
            }
        });
        students.add(new Student("王大锤",26,179.6));
        students.add(new Student("小仙女",26,178.6));
        students.add(new Student("路人甲",32,177.6));
        students.add(new Student("文艺少",27,177.6));

        System.out.println(students);
    }
}
